import { _decorator, Component, Label, Node, ProgressBar } from 'cc';
import { GAME_RES, GAME_SCENE } from '../Script/Data/GlobalData';
import { uiManager } from '../Script/Manager/UIManager/UIManager';
const { ccclass, property } = _decorator;

@ccclass('Loading')
export class Loading extends Component {

    //进度条
    @property(ProgressBar)
    private ProgressBar: ProgressBar = null;

    //加载文字
    @property(Label)
    private LoadLabel: Label = null;

    start() {

        app.gameData.Init();
        app.uiManager.Init();
        app.popManager.Init();
        app.topManager.Init();
        this.LoadLabel.string = "L0%";

        this.LoadRes();
    }

    /**
     * 加载资源
     */
    private async LoadRes() {

        await app.resManager.LoadBundle(GAME_RES.BundleName, 0.1);
        await app.resManager.LoadRes(GAME_RES.BundleName, GAME_RES.Asset.Prefabs, 0.3);
        await app.resManager.LoadRes(GAME_RES.BundleName, GAME_RES.Asset.Sounds, 0.3);
        await app.resManager.LoadRes(GAME_RES.BundleName, GAME_RES.Asset.SpriteFrames, 0.3);

        this.node.removeFromParent();

        app.audioManager.Init();
        app.audioManager.PlayBgSound();
        app.uiManager.ShowUI(GAME_SCENE.LoginScene);
    }

    update(deltaTime: number) {
        this.ProgressBar.progress = app.resManager.NowProgress;
        this.LoadLabel.string = "L" + Math.floor(app.resManager.NowProgress * 100) + "%";
    }
}


